package com.healthy.sport.demo.interceptor;

import com.healthy.sport.demo.datasource.DynamicDataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/11/10
 */
@Slf4j
public class MyHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String schoolId = request.getParameter("schoolId");
        log.info("拦截器里设置数据源为{}",schoolId);
        DynamicDataSourceContextHolder.set(schoolId);
        return true;
    }
}
